package top.glike.ssl.auto.domain.other;

import com.aliyun.sdk.service.cas20200407.models.DescribeCertificateStateResponseBody;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * packageName top.glike.ssl.auto.domain.other
 *
 * @author Sophia
 * @className CloudCertInfo
 * @description TODO 云上证书信息
 * @date 2025/10/13
 */
@Data
public class CloudCertInfo {

    /**
     * 证书pem
     */
    private String certificate;
    /**
     * 证书key
     */
    private String privateKey;
    /**
     * 证书状态
     */
    private String type;
    /**
     * 证书域名
     */
    private String domain;
    /**
     * 消息
     */
    private String message;
    /**
     * 编码
     */
    private String code;

    public CloudCertInfo() {
    }

    public CloudCertInfo(DescribeCertificateStateResponseBody body) {
        this.certificate = body.getCertificate();
        this.privateKey = body.getPrivateKey();
        this.type = body.getType();
        this.domain = body.getDomain();
        this.message = "";
        this.code = "";
    }

    public String getApplyStatus() {
        if (StringUtils.equals(this.type.toUpperCase(), "certificate".toUpperCase())) {
            return "success";
        }
        if (StringUtils.equalsAny(this.type.toUpperCase(), "verify_fail".toUpperCase(), "unknow".toUpperCase())) {
            return "fail";
        }
        return "";
    }
}
